
$myjquery = jQuery.noConflict();


function refreshDivServerStatus(){
    
    var auto_refresh = setInterval(function(){
        $myjquery('#serverstatus').fadeOut('slow').load('esa/server_test.php').fadeIn("slow");
    }, 10000);//every 9 second
}

function refreshDivUpdatePosts(){
       
        var type_page =$myjquery('#hidden_social').attr('type_page');
        //alert(type_page);
        $myjquery.post("esa/update_posts_db.php", {},
            function() {
            $myjquery('#timelines').fadeOut('slow').load('esa/'+type_page+'_timeline.php').fadeIn("slow");
        });
        Set_selected();
        
}

function refreshStats(){
        
       $myjquery.post("esa/refresh_stats.php", {} );
    
}

function updatePostsDB(){
    
    var auto_refresh = setInterval(function(){
        $myjquery('#serverupdate').fadeOut('slow').load('esa/update_posts_db.php').fadeIn("slow");
    }, 240000);//every 240 second
}



function ovv_total(param){
       
         $myjquery.get(param, function(data) {
             $myjquery('.total').html(data);
         });
}

function ovv_serverstatus(param){
       
         $myjquery.get(param, function(data) {
             $myjquery('.serverstatus').html(data);
         });
}

function ovv_serverudpate(param){
       //alert();
         $myjquery.get(param, function(data) {
             $myjquery('.serverupdate').html(data);
         });
}

function ovv_maincontent(param){
    
         $myjquery.get(param, function(data) {
             $myjquery('.maincontent').html(data);
         });
}

function ovv_othercontent(param){
    
         $myjquery.get(param, function(data) {
             $myjquery('.othercontent').html(data);
         });
}

function ovv_mainother(param){
        
         $myjquery.get(param, function(data) {
             $myjquery('.mainother').html(data);
         });
}

function ovv_social(param){
       
         $myjquery.get(param, function(data) {
             $myjquery('#social').html(data);
         });
}

function ovv_timeline(param){
   
         $myjquery.get(param, function(data) {
             $myjquery('#timelines').html(data);
         });
}


function append_timeline(param){
   
    $myjquery('#otherposts').hover(function(){
        $myjquery.get(param, function(data) {
              $myjquery('#timelines').append(data);
         })
    });
}


function checklogin(){
   
   if ((email.value == '') && (password.value == '')||(email.value=="*Email") && (password.value=="Password") ){
      $myjquery('#em').html("Email is Required!");
      $myjquery('#pa').html("Password is Required!");
      email.focus();
      return false;
   }else{
      emptydiv('em');
      emptydiv('pa'); 
      emptydiv('le');
   }
   if((password.value == '')||(password.value=="Password")) {
       $myjquery('#pa').html("Password is Required!");
      password.focus();
      return false;
   }else{
      emptydiv('pa'); 
      emptydiv('le');
   }
   if ((email.value == '')||(email.value == "*Email")) {
       $myjquery('#em').html("Email is Required!");
      email.focus();
      return false;
   }else{
      emptydiv('em');  
      emptydiv('le');
   }
   
   return true;
}


function check(){

   
   var femail;
   var fpassword;
   var fpassword1;
   var fbooth;
   var fname;
   var checkm;
  
   if ((email.value == '') || (email.value=="*Email")){
      femail=1;
   }else{
      if(checkmail(email.value)){
        
      }else{
          checkm=1;
      } 
      
   }

   if ((password.value == '')|| (password.value=="Password") ){
      fpassword=1;
      
   }else{
      fpassword=0;
   }
   if ((password1.value == '') || (password1.value=="Password")){
      fpassword1=1;
   }else{
      fpassword1=0;
   }
   if (password.value != password1.value){
      fbooth=1;
   }else{
     fbooth=0;
       
   }
    if ((companyname.value == '')  || (companyname.value=="Company name")){
      fname=1;
   }else{
      fname=0;
 
   }
   
   if(femail==1){$myjquery('#em').html("Email is Required!");}else{} 
   if(fpassword ==1){$myjquery('#pa').html("Password is Required!");}else{emptydiv('pa');}
   if(fpassword1 ==1){$myjquery('#pa1').html("Confirm Password!");}else{emptydiv('pa1');}
   if(fbooth ==1){$myjquery('#pa2').html("Passwords must the same!");}else{emptydiv('pa2');}
   if(fname ==1){$myjquery('#na').html("Name is Required!");}else{emptydiv('na');}
   
  
   if((femail==1)||(fpassword==1)|| (fpassword1==1)||(fbooth==1)||(fname==1)){ 
      //alert('false');
      return false;
   }else{
       //alert('true');
       return true;
   }
   
}

function checkmail(emailStr) {
        
        var emailPat = /^(.+)@(.+)$/;
        var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
        var validChars = "[^\\s" + specialChars + "]";
        var quotedUser = "(\"[^\"]*\")";
        var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
        var atom = validChars + "+";
        var word = "(" + atom + "|" + quotedUser + ")";
        var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
        var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
        var matchArray = emailStr.match(emailPat);
        var error1=0;

        if (matchArray == null) {
            //alert('2');
            $myjquery('#em').html("Email Format is not valid!"); 
            error1=1;
            
            //return false;
        }else{
            
            var user = matchArray[1];
            var domain = matchArray[2];
            if (user.match(userPat) == null) {
            //alert('2');
           // $myjquery('#em').html("Email Format is not valid!"); 
            //return false;
                error1=1;
            }else{
                
                var IPArray = domain.match(ipDomainPat);
                 if (IPArray != null) {
                    for (var i = 1; i <= 4; i++) {
                        if (IPArray[i] > 255) {
                     //alert('3');
                   // $myjquery('#em').html("Email Format is not valid!"); 
                    //return false;
                            error1=1;
                         }
               
                    }
                    
                }else{
                    
                    var domainArray = domain.match(domainPat);
                    if (domainArray == null) {
                    //alert('4');
                    //$myjquery('#em').html("Email Format is not valid!"); 
                    //return false;
                        error1=1;
                    }else{
                        
                        var atomPat = new RegExp(atom, "g");
                        var domArr = domain.match(atomPat);
                        var len = domArr.length;
                         if (domArr[domArr.length - 1].length < 2 || domArr[domArr.length - 1].length > 6) {
                            // alert('5');
                                //$myjquery('#em').html("Email Format is not valid!"); 

                                //return false;
                                error1=1;
                        }else{
                            
                            if (len < 2) {
           
                                //$myjquery('#em').html("Email Format is not valid!"); 
                                var errStr = "";
                                //alert(errStr);
                                //return false;
                                error1=1;
                            }else{
            
                            }
                            
                        }
        
            
                    }
        
            
                }
                    
            }
       
            
        }
        
      
        if(error1==1){$myjquery('#em').html("Email Format is not valid!");return false;}else{emptydiv('em');return true;}
        
        
        
}

function popup(apri) {
   
  var stile = "top=10, left=10, width=500, height=340, status=no, menubar=no, toolbar=no scrollbars=no"; 
  window.open(apri, "", stile);
  
}

function emptydiv(id){
    
    $myjquery('#'+id).empty();

}

function show_div(id) {
   

$myjquery('#'+id).show('slow');
}

function hide_div(id) {
   
$myjquery('#'+id).hide('slow');
}

function confirm_unassocciate(socialnetwork) {
    
   // alert(socialnetwork);
    
  if (confirm("Do you want unassociate your ESA profile from "+socialnetwork+" so that all your cached information is erased from ESA system?")) {
      
       popup('esa/unassociate.php?service='+socialnetwork);
       
  
  }
}


function setactive(active){
    

        if(active[0]== 1){
            
            $myjquery("#FBimg").removeAttr('onclick');
            $myjquery("#FBimg").attr('onclick','confirm_unassocciate("Facebook");');    
            $myjquery("#FBimg").attr('title','Facebook linked');
            $myjquery("#FBimg").addClass("check");
            $myjquery("#FBcheck").removeClass("unchecked").addClass("checked");
            
            
            
        }       
        
        if(active[1]== 1){
           
            $myjquery("#GPimg").removeAttr('onclick');
            $myjquery("#GPimg").attr('onclick','confirm_unassocciate("Google");');  
            $myjquery("#GPimg").attr('title','Google+ linked');
            $myjquery("#GPimg").addClass("check");
            $myjquery("#GPcheck").removeClass("unchecked").addClass("checked");
        }    
        
        if(active[2]== 1){
           
            $myjquery("#TWimg").removeAttr('onclick');
            $myjquery("#TWimg").attr('onclick','confirm_unassocciate("Twitter");');    
            $myjquery("#TWimg").attr('title','Twitter linked');
            $myjquery("#TWimg").addClass("check");
            $myjquery("#TWcheck").removeClass("unchecked").addClass("checked");
        }    
        
        if(active[3]== 1){
            
            $myjquery("#PIimg").removeAttr('onclick');
            $myjquery("#PIimg").attr('title','Pinterest linked');
            $myjquery("#PIcheck").removeClass("unchecked").addClass("checked");
        }    
        
        if(active[4]== 1){
            
            $myjquery("#LIimg").removeAttr('onclick');
            $myjquery("#LIimg").attr('title','LinkedIn linked');
            $myjquery("#LIcheck").removeClass("unchecked").addClass("checked");
        }    
        
        if(active[5]== 1){
           
            $myjquery("#FSimg").removeAttr('onclick');
            $myjquery("#FSimg").attr('title','FourSquare linked');
            $myjquery("#FScheck").removeClass("unchecked").addClass("checked");
        }
    
   
}

function send_data_login(){
 
 //loading
 $myjquery('#imgloading').removeClass('hidden');
// Utilizziamo il metodo .post() di jQuery per inviare una richiesta di tipo POST allo script PHP.
 
$myjquery.post("esa/login.php", {email: $myjquery('#email').val(), password: $myjquery('#password').val()},
   function(data) {
     $myjquery('.maincontent').html(data);
   });
 
}

function send_data_register(){
   
//loading   
$myjquery('#loading').removeClass('hidden');
 
// Utilizziamo il metodo .post() di jQuery per inviare una richiesta di tipo POST allo script PHP.

$myjquery.post("esa/register.php", {email: $myjquery('#email').val(), password: $myjquery('#password').val(),password1: $myjquery('#password1').val(),companyname: $myjquery('#companyname').val(), description: $myjquery('#description').val()},
   function(data) {
     $myjquery('.mainother').html(data);
   });
   
 
}
function send_data_img(){

$myjquery.post("esa/update_logo.php", {urlimg: $myjquery("#hidden_img").val()},
   function(data) {
     $myjquery('.mainother').html(data);
   });
 
}

function send_data_option_page(){

$myjquery.post("../esa/options.php", {proxy: $myjquery("#proxy").val(), id_appFB: $myjquery("#id_appFB").val(),id_keyGO: $myjquery("#id_keyGO").val(),id_secretGO: $myjquery("#id_secretGO").val(),id_keyTW: $myjquery("#id_keyTW").val(),id_secretTW: $myjquery("#id_secretTW").val()},
   function(data) {
     $myjquery('#result').html(data);
   });
 
}

function send_data_timeline(type_page,like){
   
var val1=$myjquery("#hidden_social").attr('value1');
var val2=$myjquery("#hidden_social").attr('value2');
var val3=$myjquery("#hidden_social").attr('value3');

var where_db="";

    
where_db="AND (SocialNetwork="+val1+" OR SocialNetwork="+val2+" OR SocialNetwork="+val3+") AND ( Message LIKE 1%"+like+"%1)";
 

//alert(type_page);

$myjquery.post("esa/"+type_page+"_timeline.php", {where_db:where_db},
   function(data) {
     $myjquery('#timelines').html(data);
     //$myjquery('#timelines').fadeOut('fast').load('esa/'+type_page+'_timeline.php').fadeIn("fast");
   }); 
   

 
}

function can_download_other_posts(type_page){
   
    
    $myjquery("#otherposts").click(function(){
  
    var val=$myjquery("#numberclick").attr('value');  
    var value=parseInt(val);
    
   // alert(value);
        
         $myjquery('#otherposts').remove();
         //alert();
          var jqxhr =  $myjquery.post("esa/"+type_page+"_timeline.php",{offset:(16 * value)},
            function(data) {
             
                //alert(data);
               
                $myjquery('#timeline').append(data);             
                $myjquery("#numberclick").attr('value',value+1);
               // $myjquery('#timelines').fadeOut('fast').load('esa/'+type_page+'_timeline.php',{offset:(16 * value)}).fadeIn("fast");    
                
             }); 
            
         
    });
   
   
}


function Initialize_JoptionPane(){
  
    $myjquery(function(){
	$myjquery('.scrolltimelines').jScrollPane(); 
       
    }); 
    

}

function scroll(){
                     
                 var val=$myjquery("#numberclick").attr('value'); 
                 var value=parseInt(val);  
                 //alert(value);
                 
                 $myjquery('#timelines').scrollPagination({
                    'contentPage': 'esa/home_timeline.php', // the url you are fetching the results
                    'contentData': {offset:(16 * value)}, // these are the variables you can pass to the request, for example: children().size() to know which page you are
                    'scrollTarget':  $myjquery(".scrolltimelines"), // who gonna scroll? in this example, the full window
                    'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends
                    'beforeLoad': function(){ // before load function, you can display a preloader div
                         $myjquery('#imgloading').removeClass('hidden');
                    },
                    'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements
                        //sleep(500);        
                        $myjquery('#otherposts').fadeOut('fast')    
                         var i = 0;
                          $myjquery(elementsLoaded).fadeInWithDelay();
                          
                    }
                });
                

                // code for fade in element by element
                 $myjquery.fn.fadeInWithDelay = function(){
                    var delay = 0;
                    return this.each(function(){
                         $myjquery(this).delay(delay).animate({opacity:1}, 200);
                        delay += 200;
                    });
                };
                
    
}

function sleep(milliseconds) {
    
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
  
}




function selected_img(){
   
   if(($myjquery('#imgfb').attr("src"))==($myjquery('#imgfb').attr("url_img"))){$myjquery('#imgfb').addClass("selected_img_select");}
   if(($myjquery('#imggo').attr("src"))==($myjquery('#imggo').attr("url_img"))){$myjquery('#imggo').addClass("selected_img_select");}
   if(($myjquery('#imgtw').attr("src"))==($myjquery('#imgtw').attr("url_img"))){$myjquery('#imgtw').addClass("selected_img_select");}
}
function select_img(){ 
       
    $myjquery("#imgfb").bind('click', function() {$myjquery("#hidden_img").attr('value',$myjquery('#imgfb').attr("src"));$myjquery('#imgfb').addClass("selected_img_select");$myjquery('#imggo').removeClass("selected_img_select");$myjquery('#imgtw').removeClass("selected_img_select");}); 
    $myjquery("#imggo").bind('click', function() {$myjquery("#hidden_img").attr('value',$myjquery('#imggo').attr("src"));$myjquery('#imggo').addClass("selected_img_select");$myjquery('#imgfb').removeClass("selected_img_select");$myjquery('#imgtw').removeClass("selected_img_select");});   
    $myjquery("#imgtw").bind('click', function() {$myjquery("#hidden_img").attr('value',$myjquery('#imgtw').attr("src"));$myjquery('#imgtw').addClass("selected_img_select");$myjquery('#imgfb').removeClass("selected_img_select");$myjquery('#imggo').removeClass("selected_img_select");});  
    
  
}

function select_social_network(){ 

    var type_page="";
 
   
    $myjquery("#FB").toggle(function() {
        $myjquery("#hidden_social").attr('value1',"11");
        $myjquery('#FB').removeClass("selected");
        $myjquery('#FB').attr('title','show');
        type_page=$myjquery("#hidden_social").attr('type_page'); 
        send_data_timeline(type_page,"");
        
        //alert($myjquery("#hidden_social").attr('value1'));
        }, function() {
        $myjquery("#hidden_social").attr('value1',"1Facebook1");
        $myjquery('#FB').addClass("selected");
        type_page=$myjquery("#hidden_social").attr('type_page');      
        send_data_timeline(type_page,"");
        //alert($myjquery("#hidden_social").attr('value1'));
    });
    
    $myjquery("#GP").toggle(function() {
        $myjquery("#hidden_social").attr('value2',"11");
        $myjquery('#GP').removeClass("selected");
        $myjquery('#GP').attr('title','show');
        type_page=$myjquery("#hidden_social").attr('type_page'); 
        send_data_timeline(type_page,"");
        //alert($myjquery("#hidden_social").attr('value2'));
        }, function() {
        $myjquery("#hidden_social").attr('value2',"1Google1");
        $myjquery('#GP').addClass("selected");
        type_page=$myjquery("#hidden_social").attr('type_page'); 
        send_data_timeline(type_page,"");
        
        //alert($myjquery("#hidden_social").attr('value2'));
    });
    
    $myjquery("#TW").toggle(function() {
        $myjquery("#hidden_social").attr('value3',"11");
        $myjquery('#TW').removeClass("selected");
        $myjquery('#TW').attr('title','show');
        type_page=$myjquery("#hidden_social").attr('type_page'); 
        send_data_timeline(type_page,"");
        //alert($myjquery("#hidden_social").attr('value3'));
        }, function() {
        $myjquery("#hidden_social").attr('value3',"1Twitter1");
        $myjquery('#TW').addClass("selected");
        type_page=$myjquery("#hidden_social").attr('type_page'); 
        send_data_timeline(type_page,"");
       
        //alert($myjquery("#hidden_social").attr('value3'));
    });
    
}



function placeholderIE9(){
  
   
   $myjquery(document).ready(function(e) {
        if(!$myjquery.support.placeholder) {
            $myjquery('#email').labelify({text:"label"});
            $myjquery('#password').labelify({text:"label"});
            $myjquery('#password1').labelify({text:"label"});
            $myjquery('#companyname').labelify({text:"label"});
            $myjquery('#description').labelify({text:"label"});
        } 
        
  
   });
}

jQuery(function() {
	jQuery.support.placeholder = false;
	test = document.createElement('input');
	if('placeholder' in test) jQuery.support.placeholder = true;
});

function DisableButton(){
     $myjquery("input[type=button]").addClass('greyButton');
     $myjquery("input[type=button]").attr("disabled", "disabled");
}
function EnableButton(){
     $myjquery("input[type=button]").removeClass('greyButton');
     $myjquery("input[type=button]").removeAttr("disabled", "disabled");
}

function getUrl(){
    
    var radiovalue=$myjquery("input:radio:checked").val();
    
}

function ShowSocialPanel(){
    
    $myjquery(document).ready(function() {
 
            $myjquery(".opensocial").toggle(
            function(){
            
                $myjquery("#social").fadeIn("slow");
                $myjquery("#send2").removeAttr('value');
                $myjquery("#send2").attr('value','Hide Add Social Network');
                ovv_social('esa/service.php');
            },
 
            function(){
                
                $myjquery("#social").fadeOut("slow");
                $myjquery("#send2").removeAttr('value');
                $myjquery("#send2").attr('value','Show Add Social Network');
            });
 
    });//FINE DOM
}

function ShowPostPanel(){
    
            $myjquery("#textareapost").click(
            function(){
                $myjquery("#update").fadeIn("slow");
            });
   
}


function HidePostPanel(){
    
            $myjquery("#box").hover(
            function(){
                $myjquery("#update").hide('fast');
                $myjquery("#update_message").html('');
                             
            });
   
}



function ShowButtonSelect(){
    

    $myjquery("#button_home").bind('click', function() {$myjquery("#button_home").css('background','darkcyan');$myjquery("#button_mention").css('background','#9AE3FF');$myjquery("#hidden_social").attr('type_page','home');/*Set_selected();*/});
    $myjquery("#button_mention").bind('click', function() {$myjquery("#button_home").css('background','#34C6FF');$myjquery("#button_mention").css('background','darkcyan');$myjquery("#hidden_social").attr('type_page','mention' );/*Set_selected();*/}); 
}

function Set_selected(){
    
    $myjquery('#FB').addClass("selected");
     $myjquery('#GP').addClass("selected");
      $myjquery('#TW').addClass("selected");
      /* $myjquery('#null').addClass("selected");
        $myjquery('#null').addClass("selected");
         $myjquery('#null').addClass("selected");*/
        
    
}



function AddHiddenSocial(param){
    
   /* if(param=="facebook") $myjquery("#hidden_social").attr('value1',"11");
    if(param=="google") $myjquery("#hidden_social").attr('value2',"11");
    if(param=="twitter") $myjquery("#hidden_social").attr('value3',"11");
    */
}

function search(){
   
   $myjquery('#search').bind('keyup', function() {send_data_timeline($myjquery("#hidden_social").attr('type_page'),$myjquery("#search").attr('value'))} );
}

function ReduceDiv(param){
  // alert(param);
   $myjquery(param).css('height',20);
}

function CrossPosting(id){
   
  $myjquery('#share').click(function() {
      
      $myjquery.post("esa/cross_posting.php", {socialnet:$myjquery("#select_social_post").attr('value'), post:$myjquery("textarea#textareapost").val(),id:id},
        function(data) {
              //alert();
              $myjquery('#update_message').html(data);
              $myjquery('#update_message').removeClass("hidden");
              $myjquery('#textareapost').val('');
              
    
  });
    
  //alert(id);
 
 });

}

function init_shadowbox(){
  //alert();
 Shadowbox.init({
    handleOversize: "drag",
    modal: true
});
       
}




























